/**
 * 
 */
package gopi.labs.Connector;

import gopi.labs.datarecord.DataRecord;
import gopi.labs.exceptions.InvalidAccessType;
import gopi.labs.exceptions.InvalidConnectionMode;
import gopi.labs.exceptions.InvalidDataRecord;

import java.util.ArrayList;
import java.util.List;

/**
 * @author GOPI
 * 
 */
public abstract class Device {

	private String deviceId;
	private List<NameValue> deviceAttributes;
	private AccessType accessType;

	
	public enum AccessType {PUSH, PULL, REQUEST, CONTINUOUS};
	
	public Device(String deviceId) {
		this.deviceId = deviceId;
		deviceAttributes = new ArrayList<NameValue>();
	}
	public abstract void defineDataRecord(DataRecord dataRecord);
	
	public void validate() throws InvalidAccessType, InvalidDataRecord, InvalidConnectionMode
	{
		checkAccessType(this.accessType);
		
	}
	public AccessType getAccessType() {
		return accessType;
	}
	public void setAccessType(AccessType accessType) throws InvalidAccessType {
		checkAccessType(accessType);
		this.accessType = accessType;
	}
	public void addDeviceAttribute(NameValue nameValue) {
		this.deviceAttributes.add(nameValue);
	}
	
	public void checkAccessType(AccessType accessType) throws InvalidAccessType {

		if (accessType != AccessType.CONTINUOUS && 
				accessType != AccessType.REQUEST &&
				accessType != AccessType.PUSH &&
				accessType != AccessType.PULL) 
			throw new InvalidAccessType(accessType != null ? accessType.toString():"");
		
	}
	public List<NameValue> getDeviceAttributes()
	{
		return this.deviceAttributes;
	}
	
	@Override
	public String toString() {
		return "Device [deviceId=" + deviceId + ", deviceAttributes="
				+ deviceAttributes + ", accessType=" + accessType
				+ "]";
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
